<template>
  <section class="menu_container">
    <section class="menu_left">
      <ul>
        <li class="menu_left_li" :class="{act: index === majorSelected}" v-for="(item, index) in appCategoryFirst" @click="setType(index, item.id)">{{item.appCategoryName}}</li>
      </ul>
    </section>
    <section class="menu_right">
      <dl v-for="(item, index) in appCategorySecond" >
        <dt  @click="showDd(index)" :class="{act: (selected == index) }">{{item.appCategoryName}}<i></i></dt>
          <dd  v-for="(item2, index2) in item.categoryModelList" :class="{hid: (selected == index) }" ><router-link :to="{path: 'searchList', query: { searchWord: '', categoryId: item2.id }}">{{item2.appCategoryName}}</router-link> </dd>
      </dl>
    </section>
  </section>
</template>
<script>
import HeaderBar from '@/components/HeaderBar.vue'
import footGuide from '@/components/footer.vue'
import { Toast } from 'mint-ui'
import qs from 'qs';
export default {
  name: 'index',
  components: {
    'header-bar': HeaderBar,
    footGuide
  },
  data () {
    return {
      isDd: false,
      selected: 555,
      majorSelected: 0,
      appCategoryFirst: null,
      appCategorySecond: null,
      categoryModelList: null,
      id: null
    }
  },
  created () {
    this.getCateFirst()
  },
  methods: {
    showDd (index) {
      this.selected = index;
    },
    getCatethree () {

    },
    goSearch () {
      this.$router.push('/search')
    },
    getCateFirst () {
      var self = this
      this.$http.post(this.url + 'api/categoryTreeOne?code=' + this.code)
        .then(function (response) {
          self.appCategoryFirst = response.data;
          self.id = response.data[0].id
          self.setType(0, self.id)
          console.log(response.data);
        })
       .catch((err) => {
         console.log(err);
         Toast('网络请求超时');
       });
    },
    setType (index, id) {
      this.majorSelected = index
      this.id = id
      this.getCateSecond(id)
    },
    getCateSecond (id) {
      var self = this
      this.loading = true
      this.$http.post(this.url + 'api/categoryTreeTwoAndThree', qs.stringify({
        code: this.code,
        id: id
      })
      )
        .then(function (response) {
          self.appCategorySecond = response.data;
          console.log(response.data);
        })
       .catch(function (error) {
         console.log(error);
         Toast('网络请求超时');
       });
    }
  }
}
</script>
